import type { Ref } from 'vue'
import { throttle } from '@/utils/throttle'
export default function useLoadMore(element:Ref<null | HTMLElement>, fn:Function) {
  function loadMore() {
    // 获取可视区域高度
    const clientHeight = element.value?.clientHeight
    const scrollTop = element.value?.scrollTop
    const scrollHeight = element.value?.scrollHeight
    if (clientHeight! + scrollTop! + 10 >= scrollHeight!) {
      fn()
    }
  }
  element.value?.addEventListener('scroll', throttle(loadMore, 1000), true)
}